package com.eric.windows.imgDispose;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;

import org.androidannotations.annotations.AfterInject;
import org.androidannotations.annotations.EView;

/**
 * <h3>Description</h3>
 * TODO
 * <h3>Author</h3> Eric
 * <h3>Date</h3> 2017/8/15 10:05
 * <h3>Copyright</h3> Copyright (c)2017 Shenzhen TLIT  Co., Ltd. Inc. All rights reserved.
 */
@EView
public class TextCanvasView extends View {


    Path[] paths = new  Path[3];
    Paint  paint ;


    public TextCanvasView(Context context) {
        super(context);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public TextCanvasView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public TextCanvasView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public TextCanvasView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @AfterInject
    void initData(){
        paths[0] = new Path();
        paths[0].moveTo(0,0);
        for (int i = 0; i <=7 ; i++) {
            paths[0].lineTo(i*30,(float)Math.random()*60);
        }
        paths[1] = new Path();
        RectF  rectf = new RectF(0,0,200,120);
        // CCW:counter-clockwise  逆时针绘制
        paths[1].addOval(rectf, Path.Direction.CCW);

        paths[2] = new Path();
        paths[2].addArc(rectf,60,180);

        //初始画笔
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(Color.GRAY);
        paint.setStrokeWidth(1);

    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawColor(Color.WHITE);
        canvas.translate(40,40);

        paint.setTextAlign(Paint.Align.RIGHT);
        paint.setTextSize(20);

        paint.setStyle(Paint.Style.STROKE);
        canvas.drawPath(paths[0],paint);
        paint.setStyle(Paint.Style.FILL);
        //float hOffset  : 与路径起始点的水平偏移距离  float vOffset  : 与路径中心的垂直偏移量
        canvas.drawTextOnPath("欢迎来到 Android",paths[0],-8,20,paint);

        //下移80
        canvas.translate(0,80);
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawPath(paths[1],paint);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawTextOnPath("欢迎来到 Android",paths[1],-60,20,paint);

        canvas.translate(0,150);
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawPath(paths[2],paint);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawTextOnPath("欢迎来到 Android",paths[2],-10,20,paint);

        canvas.translate(120,150);
        //参数一 画布在x方向上倾斜相应的角度，sx倾斜角度的tan值
        //参数二 画布在y轴方向上倾斜相应的角度，sy为倾斜角度的tan值
        canvas.skew(1,0);
        paint.setStyle(Paint.Style.STROKE);
        //参数二 三 x、y 绘制文本的圆心（x,y）
        canvas.drawText("欢迎来到 Android",0,20,paint);
    }
}
